package neusoft.example.com.yuejian06.Model;

import java.util.List;

import neusoft.example.com.yuejian06.Bean.Picture;
import neusoft.example.com.yuejian06.PublicActivity;
import neusoft.example.com.yuejian06.RetrofitListener;
import neusoft.example.com.yuejian06.Service.PictureService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class PictureModel {
    private Retrofit retrofit;
    private PictureService service;
    private PublicActivity publicActivity;
    //private RetrofitListener listener;

    public PictureModel(){
        publicActivity= new PublicActivity();
        retrofit=new Retrofit.Builder()
                .baseUrl(publicActivity.getIp()+"api/Picture/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        service = retrofit.create(PictureService.class);
    }
    public void getPicture(String picture_id, final RetrofitListener<Picture> picturelistener){
        Call<Picture> call=service.getPicture(picture_id);
        call.enqueue(new Callback<Picture>(){

            @Override
            public void onResponse(Call<Picture> call, Response<Picture> response) {
                if(response.isSuccessful() && response!=null){
                    picturelistener.onResponse(response.body());
                }else{
                    picturelistener.onFail("图片的！");//
                }

            }

            @Override
            public void onFailure(Call<Picture> call, Throwable t) {
                picturelistener .onFail(t.toString());
            }
        });

    }


}
